//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.PlugIns.Selectors {
    /// <summary>Selects whether or not to follow links depending on if the link stays on the same host as its parent.</summary>
    public class StayOnHostSelector : Eas.WebCrawler.PlugIns.Selectors.ConditionalSelector{
        /// <summary>Constructs a <see cref="StayOnHostSelector"/> from a selector to use if the requests stay on the same host as their parent and a selector to use if the link leaves its parent's host.</summary>
        /// <param name="sameHostSelector">A selector to use in those cases where the request stays on the same host as the parent request.</param>
        /// <param name="differentHostSelector">A selector to use in those cases where the request leaves the host of the parent request.</param>
        public StayOnHostSelector(Eas.WebCrawler.Interfaces.LinkSelector sameHostSelector, Eas.WebCrawler.Interfaces.LinkSelector differentHostSelector)
            :base(sameHostSelector, differentHostSelector, null)
        {
            this.ConditionalDelegate = (RequestFilterDelegate)delegate(Eas.WebCrawler.Interfaces.Request request) { return (request.Parent == null || request.Parent.Uri.Host == request.Uri.Host); };
        }
    }
}
